<html>
<head><meta charset="utf-8"><title>Slice wraps around address space · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html">Slice wraps around address space</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="163579836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163579836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163579836">(Apr 17 2019 at 16:57)</a>:</h4>
<p>Is it legal to have a slice of u8 that starts at, say, address <code>!0 - 0xff</code> with a length of 512?</p>



<a name="163579873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163579873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163579873">(Apr 17 2019 at 16:57)</a>:</h4>
<p>maybe no because one of the elements is at address 0, which it's not legal to have a reference to</p>



<a name="163579946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163579946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163579946">(Apr 17 2019 at 16:58)</a>:</h4>
<p>what if you have a slice of structs that you happen to have aligned such that no field is at address 0?</p>



<a name="163580262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163580262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163580262">(Apr 17 2019 at 17:02)</a>:</h4>
<p>not sure how to actually make such a struct because 0 is aligned for all alignments</p>



<a name="163580711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163580711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163580711">(Apr 17 2019 at 17:08)</a>:</h4>
<p>no, address computation must not overflow</p>



<a name="163580963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163580963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163580963">(Apr 17 2019 at 17:11)</a>:</h4>
<p>makes sense</p>



<a name="163580970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163580970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163580970">(Apr 17 2019 at 17:11)</a>:</h4>
<p>how strict is that?</p>



<a name="163581027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581027">(Apr 17 2019 at 17:12)</a>:</h4>
<p>is it invalid to create a fat raw pointer with a length that's too long?</p>



<a name="163581093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581093">(Apr 17 2019 at 17:12)</a>:</h4>
<p>or is it just for references</p>



<a name="163581610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581610">(Apr 17 2019 at 17:18)</a>:</h4>
<p>uh. no idea.^^</p>



<a name="163581629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581629">(Apr 17 2019 at 17:19)</a>:</h4>
<p>this is essnetially the question of whether raw fat ptr metadata must be valid, which is not decided</p>



<a name="163581643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581643">(Apr 17 2019 at 17:19)</a>:</h4>
<p>but even if you can <em>have</em> the raw ptr, you'd not be allowed to <em>use</em> it</p>



<a name="163581681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581681">(Apr 17 2019 at 17:19)</a>:</h4>
<p>sure</p>



<a name="163581754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581754">(Apr 17 2019 at 17:20)</a>:</h4>
<p>mostly a question of whether I need to check validity before creating the pointer or whether I can do it after</p>



<a name="163581873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163581873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163581873">(Apr 17 2019 at 17:21)</a>:</h4>
<p>I guess I'm creating the fat pointer by calling slice::from_raw_parts and then converting it to a pointer, which I suppose is always invalid</p>



<a name="163584086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Slice%20wraps%20around%20address%20space/near/163584086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Slice.20wraps.20around.20address.20space.html#163584086">(Apr 17 2019 at 17:44)</a>:</h4>
<p>yeah then you have a reference (for a short time)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>